$J(document).ready(function(){ 
	DTLock.init();
}); 

var DTLock={
		id :null,
		testInterval :null,
		parmData:{},//组装参数
		init:function(){
			this.addLisen();
		},
		//测试方法
	  test:function(parm,url) {
		  var o=this;
			$J.ajax({
				type : 'post',
				url : url,
				dataType : 'json',
				contentType: "application/json",
				data:parm?$J.toJSON(parm):null,
				async : true,
				cache : false,
				success : function(data) {
					if (data.status == false) {
						if (data.msg)
							alert(data.msg);
						return;
					}
					alert("操作成功！");
					location.reload();
				},
				error : function(data) {
					$J("#msg").html(data.msg);
				}
			});
		},
		//注册事件
		addLisen:function(){
			var o=this;
			$J('body').on('click', '#addTest', function() {
				o.id = $J(this).attr("name");
				o.testInterval= $J("#"+o.id+"_testInterval").val();
				o.testCount= $J("#"+o.id+"_testCount").val();
				if(o.testInterval==null||o.testInterval==""||typeof(o.testInterval) == "undefined"){
					alert("测试周期不能为空");
					return;
				}
		  		o.parmData.testInterval=o.testInterval;
		  		o.parmData.id=o.id;
				if(o.testCount&&o.testCount!=""){
			  		o.parmData.testCount=o.testCount;
			  	}
				o.test(o.parmData,window.baseUrl + "/test/addTest");
			});
			
			$J('body').on('click', '#stopTest', function() {
				o.id = $J(this).attr("name");
		  		o.test(o.parmData,window.baseUrl + "/test/stopTest/"+o.id);
			});

			$J('body').on('click', '#continueTest', function() {
				o.id = $J(this).attr("name");
		  		o.test(o.parmData,window.baseUrl + "/test/continueTest/"+o.id);
			});

			$J('body').on('click', '#removeTest', function() {
				o.id = $J(this).attr("name");
		  		o.test(o.parmData,window.baseUrl + "/test/removeTest/"+o.id);
			});
		}
}